<template>
  <div>
  <!-- 头部导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <el-row>
        <el-col :span="8">
           <el-input
            placeholder="请输入内容"
            class="input-with-select">
            <template #append>
              <el-button icon="el-icon-search"></el-button>
            </template>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格区域 -->
      <el-table :data="orderList" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template v-slot="scope">
            <el-tag v-if="scope.row.pay_status == '1'" type="success">已付款</el-tag>
            <el-tag v-else type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货">
          <template v-slot="scope">
            <template>
               {{scope.row.is_send}}
            </template> 
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template v-slot="scope">
            {{scope.row.create_time | dataFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
             <el-button type="primary" icon="el-icon-edit" size="mini" @click="showClick()"></el-button>
             <el-button type="success" icon="el-icon-location" size="mini" @click="propressClick()"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-Page="queryInfo.pagenum"
      :page-size="queryInfo.pagesize"
      :page-sizes="[5, 10, 15, 20]"
      layout="total, prev, pager, next, jumper, sizes"
      :total="total">
    </el-pagination>
    </el-card>
    <!-- 弹出修改地址对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="addressVisible"
      width="50%"
      @close="addressClose()">
      <el-form ref="addressFormRef" :model="addressForm" label-width="100px" :rules="addressFormRules">
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader v-model="addressForm.address1" :options="cityData"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>  
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="addressVisible = false">取 消</el-button>
          <el-button type="primary" @click="addressVisible = false">确 定</el-button>
        </span>
      </template>
    </el-dialog>
    <!-- 物流信息弹出框 -->
    <el-dialog
      title="物流信息"
      :visible.sync="propressVisible"
      width="50%">
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="propressVisible = false">取 消</el-button>
          <el-button type="primary" @click="propressVisible = false">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import cityData from "./citydata"
export default {
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orderList: [],
      total: 0,
      addressVisible: false,
      addressForm: {
        address1: [],
        address2: ''
      },
      addressFormRules: {
        address1: [
          { required: true,message: "请城市地址",trigger: 'blur'}
        ],
        address2: [
          { required: true,message: "请输入详细地址",trigger: 'blur'}
        ]
      },
      cityData,
      propressVisible: false,
      propressInfo: []
    }
  },
  created() {
    this.getOrdersList()
  },
  methods: {
    async getOrdersList() {
      const {data:res} = await this.$http.get('orders', {params: this.queryInfo})
      if(res.meta.status !== 200) {
        return this.$message.error('获取订单列表失败！')
      }
      this.$message.success('获取订单列表成功！')
      this.total = res.data.total
      this.orderList = res.data.goods
      console.log(this.orderList);
    },
    handleSizeChange(newsize) {
      this.queryInfo.pagesize = newsize
      this.getOrdersList()
    },
    handleCurrentChange(newnum) {
      this.queryInfo.pagenum = newnum
      this.getOrdersList()
    },
    showClick() {
      this.addressVisible = true
    },
    addressClose() {
      this.$refs.addressFormRef.resetFields()
    },
    propressClick() {
    // const {data:res} = await this.$http.get('/kuaidi/804909574412544580')
    // if(res.meta.status !== 200) {
    //   return this.$message.error('获取物流信息失败！')
    // }
    // this.$message.success('获取物流信息成功！')
    // this.propressInfo = res.data
    this.propressVisible = true
  }

  },
  
}
</script>

<style>
.el-card {
  margin-top: 15px;

}
.el-table {
  margin-top: 15px;
}
.el-cascader {
  width: 100%;
}
</style>